<?php
/**
 * | @author 韩威兵^life <1877361302@qq.com>
 * +----------------------------------------------------------------------
 * | @copyright 2016 - 2019 HQ
 * +----------------------------------------------------------------------
 * | @version $Id: 2019/4/27 10:46 jiahe_new Food.php 韩威兵^life $
 * +----------------------------------------------------------------------
 */

namespace app\api\controller;

use app\api\server\food\FoodServer;
use app\api\server\member\memberServer;
use app\common\common\model\oldModel\goods\Goods;
use app\common\common\model\oldModel\goods\StoreGoods;
use app\common\common\Server\commonServer;
use app\common\common\Server\dingSendErrorMsgServer;
use app\common\library\token\driver\Redis;
use think\Db;
use think\Log;

class  Food extends Base {

    public function test(){
        //echo 89;exit;
print_r(dingSendErrorMsgServer::sengMsg('nimenhao'));

    }

    /**
     *首页菜品
     */
    public function foodlist(){
        try{
            $store_id = input('store_id', 0) ;
            $key = input('key', '');
            if(empty($store_id)){
                commonServer::error(2)->exits();
            }
            //特殊密钥无需校验
            $update_status = false;
            if($key == 'huangqingweibinggaopengpengbuo'){
                $member_info = ['store_id'=>$store_id];
                $update_status = true;
            }else{
                $member_info = (new memberServer())->checkCiphertext($key);
                if($member_info === false){
                    commonServer::error(2)->exits();
                }
            }

            $food_obj = new FoodServer();
            //查询是否有热点数据需要跟新, false:读取缓存数据即可
            if(!$update_status){
                $update_status = $food_obj->isUpdateGoods();
            }

            $list = $food_obj->getList($store_id, $update_status);

            //加密信息
            $member_info['store_id'] = $store_id;
            $list['key'] = (new memberServer())->encryptionMemberInfo($member_info);

            commonServer::success([], '成功', $list)->exits();

        }catch (\Exception $e){
            $err = formatErr($e);
            commonServer::error(99997,[], $err)->exits();
        }
        //todo aw: 这里需要有弹出广告的功能，可能第一期不考虑，但是还是尽可能的想到
    }



}  